home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SAMPLES.BIN / QuitDialog.java < prev    next >
Encoding:
Java Source  |  1996-12-08  |  1.9 KB  |  74 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class QuitDialog extends Dialog {
  8.     void yesButton_Clicked(Event event) {
  9.         getParent().handleEvent(new Event(this, Event.WINDOW_DESTROY, null));
  10.     }
  11.  
  12.     void noButton_Clicked(Event event) {
  13.         //{{CONNECTION
  14.         // Clicked from noButton Hide the Dialog
  15.         hide();
  16.         //}}
  17.     }
  18.  
  19.     public QuitDialog(Frame parent, boolean modal) {
  20.  
  21.         super(parent, modal);
  22.  
  23.         //{{INIT_CONTROLS
  24.         setLayout(new FlowLayout(FlowLayout.CENTER,20,10));
  25.         addNotify();
  26.         resize(insets().left + insets().right + 317,insets().top + insets().bottom + 97);
  27.         yesButton = new java.awt.Button(" Y e s ");
  28.         yesButton.reshape(insets().left + 84,insets().top + 5,73,32);
  29.         yesButton.setFont(new Font("Dialog", Font.BOLD, 20));
  30.         add(yesButton);
  31.         noButton = new java.awt.Button("  N o  ");
  32.         noButton.reshape(insets().left + 162,insets().top + 5,71,32);
  33.         noButton.setFont(new Font("Dialog", Font.BOLD, 20));
  34.         add(noButton);
  35.         setTitle("Really Quit?");
  36.         setResizable(false);
  37.         //}}
  38.     }
  39.  
  40.     public QuitDialog(Frame parent, String title, boolean modal) {
  41.         this(parent, modal);
  42.         setTitle(title);
  43.     }
  44.  
  45.     public synchronized void show() {
  46.         Rectangle bounds = getParent().bounds();
  47.         Rectangle abounds = bounds();
  48.  
  49.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  50.              bounds.y + (bounds.height - abounds.height)/2);
  51.  
  52.         super.show();
  53.     }
  54.  
  55.     public boolean handleEvent(Event event) {
  56.         if(event.id == Event.WINDOW_DESTROY) {
  57.             hide();
  58.             return true;
  59.         }
  60.         if (event.target == noButton && event.id == Event.ACTION_EVENT) {
  61.             noButton_Clicked(event);
  62.         }
  63.         if (event.target == yesButton && event.id == Event.ACTION_EVENT) {
  64.             yesButton_Clicked(event);
  65.         }
  66.         return super.handleEvent(event);
  67.     }
  68.  
  69.     //{{DECLARE_CONTROLS
  70.     java.awt.Button yesButton;
  71.     java.awt.Button noButton;
  72.     //}}
  73. }
  74.